package org.hhchat.leetcode.stack;

import java.util.Stack;

public class code682 {

    static class Solution {
        public int calPoints(String[] ops) {
            Stack<Integer> rounds = new Stack<>();
            int sum = 0;
            Stack<Integer> stack = new Stack<>();
            for (String op : ops) {
                switch (op) {
                    case "C":
                        sum -= stack.pop();
                        break;
                    case "D":
                        int round = stack.peek() * 2;
                        sum += round;
                        stack.push(round);
                        break;
                    case "+":
                        int a = stack.pop();
                        int b = stack.pop();
                        int roundp = a+b;
                        sum += roundp;
                        stack.push(b);
                        stack.push(a);
                        stack.push(roundp);
                        break;
                    default:
                        int num = Integer.valueOf(op);
                        sum += stack.push(num);
                        break;
                }
            }
            return sum;
        }
    }

    public static void main(String[] args) {
        Solution solution = new Solution();
        String[] strings = {"5","-2","4","C","D","9","+","+"};
        System.out.println(solution.calPoints(strings));
    }
}
